export default {
  data() {
    return {
      staffSelect: [], //员工下拉框列表
      workTypeSelect: [], //工种下拉框列表
      departmentSelect: [], //部门下拉框列表
      positionSelect: [], //职位下拉框列表
      groupSelect: [], //组别下拉框列表
      roleSelect: [], //角色下拉框列表
      departmentTree: [], //部门树
    }
  },
  methods: {
    /**
      * 获取部门下拉框列表
     */
    getDepartmentSelect() {
      return new Promise(resolve => {
        this.$http({
          url: this.$http.adornUrl('/hanger/department/get-all-department'),
          method: 'post',
          data: {
            data: this.$store.getters.unitId
          }
        }).then(({
          data
        }) => {
          if (data.code == 200) {
            this.departmentSelect = data.data.map(v => {
              return {
                label: v.departmentName,
                value: v.departmentId
              }
            });
          } else {
            this.$message.error(data.errorMessage);
          }
          resolve(data)
        }).catch(err => {
          resolve(false)
        });
      })
    },
    /**
      * 获取部门树列表
     */
    getDepartmentTree(stuffId='') {
      this.$http({
        url: this.$http.adornUrl('/hanger/department/get-department-tree'),
        method: 'post',
        data: this.$http.adornData({
          data: {
            stuffId,
            unitId: this.$store.getters.unitId
          }
        })
      }).then(({
        data
      }) => {
        if (data.code == 200) {
          this.departmentTree=data.data;
        } else {
          this.$message.error(data.errorMessage);
        }
      })
    },
    /**
      * 获取员工下拉框列表
     */
    getStaffSelect() {
      return new Promise(resolve => {
        this.$http({
          url: this.$http.adornUrl('/hanger/stuff/get-all-stuff'),
          method: 'post',
          data: {
            data: this.$store.getters.unitId
          }
        }).then(({
          data
        }) => {
          if (data.code == 200) {
            this.staffSelect = data.data.map(v => {
              return {
                label: v.stuffName,
                value: v.stuffId
              }
            });
          } else {
            this.$message.error(data.errorMessage);
          }
          resolve(data)
        }).catch(err => {
          resolve(false)
        });
      })
    },
    /**
     * 获取工种下拉框列表
     */
    getWorkTypeList() {
      return new Promise(resolve => {
        this.$http({
          url: this.$http.adornUrl('/hanger/work-type/get-work-type-list'),
          method: 'post',
          data: {
            data: this.$store.getters.unitId
          }
        }).then(({
          data
        }) => {
          if (data.code == 200) {
            this.workTypeSelect=data.data.map(v=>{
              return {
                label:v.workTypeName,
                value:v.workTypeId
              }
            });
          } else {
            this.$message.error(data.errorMessage);
          }
          resolve(data)
        }).catch(err => {
          resolve(false)
        });
      })
    },
    /**
     * 获取职位下拉框列表
     */
    getPositionList() {
      return new Promise(resolve => {
        this.$http({
          url: this.$http.adornUrl('/hanger/position/get-position-list'),
          method: 'post',
          data: {
            data: this.$store.getters.unitId
          }
        }).then(({
          data
        }) => {
          if (data.code == 200) {
            this.positionSelect=data.data.map(v=>{
              return {
                label:v.positionName,
                value:v.positionId
              }
            });
          } else {
            this.$message.error(data.errorMessage);
          }
          resolve(data)
        }).catch(err => {
          resolve(false)
        });
      })
    },
    /**
     * 获取组别下拉框列表
     */
    getGroupSelect() {
      return new Promise(resolve => {
        this.$http({
          url: this.$http.adornUrl('/hanger/roster/group/get-group-list'),
          method: 'post',
          data: {
            data: this.$store.getters.unitId
          }
        }).then(({
          data
        }) => {
          if (data.code == 200) {
            this.groupSelect=data.data.map(v=>{
              return {
                label:v.groupName,
                value:v.groupId
              }
            });
          } else {
            this.$message.error(data.errorMessage);
          }
          resolve(data)
        }).catch(err => {
          resolve(false)
        });
      })
    },
    /**
     * 获取角色下拉框列表
     */
    getRoleSelect() {
      return new Promise(resolve => {
        this.$http({
          url: this.$http.adornUrl('/hanger/sys/role/get-role-list'),
          method: 'post',
          data: {
            data: this.$store.getters.unitId
          }
        }).then(({
          data
        }) => {
          if (data.code == 200) {
            this.roleSelect=data.data.map(v=>{
              return {
                label:v.roleName,
                value:v.roleId
              }
            });
          } else {
            this.$message.error(data.errorMessage);
          }
          resolve(data)
        }).catch(err => {
          resolve(false)
        });
      })
    },
  },
}
